package com.dsw.rebbit.consumers;

import com.dsw.rebbit.utils.ConnectionUtils;
import com.rabbitmq.client.*;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消费者
 */
public class Consumer {
    private static final String QUEUE_NAME = "QUEUE_PRODUCERS";
    @Test
    public static void main(String [] ar) throws IOException, TimeoutException {
        /* 获取一个连接 */
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        DefaultConsumer consumer = new DefaultConsumer(channel) {    //获取到达的消息
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties
                    properties, byte[] body) throws IOException {
                String message = new String(body, "UTF-8");
                System.out.println(" ----------------11" + message);
            }
        };
        //监听队列   \
        channel.basicConsume(QUEUE_NAME, true, consumer);
    }
}
